﻿Imports BUS

Public Class frmThemQuetThe

    Public dsDsDuLieuQuet As DataTable

    Public _manv As String
    Public Property MANV() As String
        Get
            Return _manv
        End Get
        Set(ByVal value As String)
            _manv = value
        End Set
    End Property

    Public _ngay As DateTime
    Public Property NGAY() As DateTime
        Get
            Return _ngay
        End Get
        Set(ByVal value As DateTime)
            _ngay = value
        End Set
    End Property

    'Public _gio As List(Of String)
    'Public Property GIO() As List(Of String)
    '    Get
    '        Return _gio
    '    End Get
    '    Set(ByVal value As List(Of String))
    '        _gio = value
    '    End Set
    'End Property

    Private Sub frmThemQuetThe_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        dtgio.Value = "#" & Date.Now.Date & " " & "00:00:00" & "#"
        dsDsDuLieuQuet = Me.Tag
    End Sub

    Private Sub btnthem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnthem.Click
        Try
            Dim sql As String = "insert into DanhSachQuenQuetThe(manv, ngay, gio) values(N'" &
                MANV & "', '" & String.Format("{0:yyyy-MM-dd}", NGAY) & "', '" & String.Format("{0:HH:mm:ss}", dtgio.Value) & "')"
            ProcFuncBus.ExecuteProcSQL(sql)

            sql = "exec sp_congtheongay N'" & MANV & "', '" & NGAY & "'"

            ProcFuncBus.ExecuteProcSQL(sql)

            Dim dr As DataRow = dsDsDuLieuQuet.Select("Ngày='" & NGAY & "'")(0)
            Dim insT As String = String.Format("{0:HH:mm:ss}", dtgio.Value)
            For i As Integer = 1 To 10 Step 1
                If dr(i.ToString()).ToString <> "" Then
                    If (DateTime.Compare(DateTime.Parse(dr(i.ToString())), DateTime.Parse(insT)) > 0) Then
                        Dim temp As String = dr(i.ToString()).ToString
                        dr(i.ToString()) = insT
                        insT = temp
                    End If
                Else
                    dr(i.ToString()) = insT
                    Exit For
                End If
            Next

            frmDuLieuQuet.dgvdulieuquet.DataSource = dsDsDuLieuQuet

            MessageBox.Show("Da them du lieu")
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
    End Sub
End Class